package cn.cntv.app.ipanda.service.impl;
import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;
import cn.cntv.app.ipanda.custom.GsonRequest;
import cn.cntv.app.ipanda.dao.HttpDao;
import cn.cntv.app.ipanda.dao.impl.HttpDaoImpl;
import cn.cntv.app.ipanda.service.HttpService;

/**
 * @author Xiao JinLai
 * @Date 2015-12-09 15:12
 * @Description: Http 获取数据处理类
 */
public class HttpServiceImpl<T> implements HttpService<T> {

    private HttpDao mHttpDao;

    public HttpServiceImpl() {

        mHttpDao = HttpDaoImpl.getInstance();
    }

    /**
     * 获取 String 格式的数据
     * @param url
     * @param successListener
     * @param errorListener
     */
    @Override
    public void getString(String url, Response.Listener successListener, Response.ErrorListener errorListener) {

        mHttpDao.addRequest(new StringRequest(url, successListener, errorListener));
    }

    /**
     * 获取 Json 格式的数据
     * @param url
     * @param clas
     * @param successListener
     * @param errorListener
     */
    @Override
    public void getJson(String url,Class<T> clas, Response.Listener successListener, Response.ErrorListener errorListener) {

        mHttpDao.addRequest(new GsonRequest(url,clas,successListener,errorListener));
    }

}
